<template>
	<div>
		<div class="container">
			<u--input placeholder="考试名称" border="surround" v-model="thing1"></u--input>
			<u--input placeholder="考试时间" border="surround" v-model="time2"></u--input>
			<u--input placeholder="面试时间" border="surround" v-model="time4"></u--input>
			<u--input placeholder="备注说明" border="surround" v-model="thing3"></u--input>
			<u--input placeholder="跳转页面" border="surround" v-model="page"></u--input>
			<u-button type="primary" text="确定" @click="send(userOpenid[0])"></u-button>
		</div>
	</div>
</template>

<script>
import { mapActions } from 'vuex';
const db = wx.cloud.database();
import share from '../../common/share/index.vue';
export default {
	data() {
		return {
			thing1: "2023黑龙江省考面试",
			time2: "3月15日",
			time4: "面试时间",
			thing3: "结构化&结构化小组",
			page: "pages/index/index", 
			templateId: "ijk37JxZifzugbW4-Nr42l6eAunKrBcZD7_m5laCsek",
			userOpenid: [],
			index: 0
		};
	},

	onShow() {},
	onPullDownRefresh() {
		console.log('refresh');
		setTimeout(function() {
			uni.stopPullDownRefresh();
		}, 1000);
	},
	onLoad(options) {},
	computed: {},
	mounted() {
		this.getDyyh()
	},
	created() {},
	methods: {
		getDyyh(){
			let that = this
			wx.cloud.callFunction({
				name: "get",
				data: {
					fncname: "user_subscribe"
				},
				success: function(res){
					that.userOpenid = res.result.data.map(item => item._openid)
				},
				fail: function(req){
					console.log(req)
				}
			})
		},
		send(openid) {
			let that = this;
			let data = {
				templateId: that.templateId,
				_openid: openid,
				page: that.page,
				subMsg: {
					thing1: {
						value: that.thing1
					},
					time2: {
						value: that.time2
					},
					time4: {
						value: that.time2
					},
					thing3: {
						value: that.thing6
					}
				}
			}
			wx.cloud.callFunction({
				name: 'sendDyMsg',
				data: data,
				success:function(res){
					console.log("发送成功")
					
					if(that.index < that.userOpenid.length - 1){
						that.index += 1
						that.send(that.userOpenid[that.index])
					}
				},
				fail: function(req){
					console.log("发送失败",req)
					if(that.index < that.userOpenid.length - 1){
						that.index += 1
						that.send(that.userOpenid[that.index])
					}
				}
			})
				
			
		}
	},
	components: {}
};
</script>

<style lang="scss">
// @import url(./index.css);
</style>
